package com.chen.manager.service.impl;

import com.chen.manager.mapper.BrandMapper;
import com.chen.manager.service.BrandService;
import com.chen.model.entity.product.Brand;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author cgj
 * @date 3/4/25 3:29 PM
 */
@Service
@Transactional
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    /**
     * 分页查询brand
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(readOnly = true)
    @Override
    public PageInfo<Brand> showByPage(Integer pageNum, Integer pageSize) {
        //开启分页,必须在代码的第一行
        PageHelper.startPage(pageNum,pageSize);
        List<Brand> brandList =brandMapper.selectByPage();
        return new PageInfo<>(brandList) ;
    }

    /**
     * 新增品牌
     * @param brand
     */
    @Override
    public void save(Brand brand) {
         brandMapper.insertBrand(brand);
    }

    /**
     * 修改品牌
     * @param brand
     */
    @Override
    public void edit(Brand brand) {
         brandMapper.updateBrand(brand);
    }

    /**
     * 根据id删除品牌
     * @param id
     */
    @Override
    public void deleteBrandById(Long id) {
        brandMapper.deleteBrandById(id);
    }

    /**
     * 查询全部品牌
     * @return
     */
    @Override
    public List<Brand> findAll() {
        List<Brand> brandList= brandMapper.findAll();
        return brandList;
    }

    /**
     * 根据分类查询品牌id
     * @param categoryId
     * @return
     */
    @Transactional(readOnly = true)
    @Override
    public List<Brand> selectBrandByCategoryId(Long categoryId) {
        List<Brand> brandList=brandMapper.selectBrandByCategoryId(categoryId);
        return brandList;
    }
}
